<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata"
			:initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				zposId: "",
				reportTime: "",
				oUserId: "",
				postId: "",
				indexRegisterCache:'ckd-zb-anytimereport-indexRegister-cache'
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		methods: {
			initLoad() {
				
			},
			// onSelectIndexDict(item) {
			// 	let _that = this
			// 	let formdata = _that.$refs.autoform.formdata
			// 	formdata.indexUnitName = item.indexUnitName
			// 	_that.om.request(
			// 		"anyTimeReport/getOtherOptions", {
			// 			zposId: _that.zposId,
			// 			zuserId: _that.userId,
			// 			userId: _that.oUserId,
			// 			postId: _that.postId,
			// 			reportTime: _that.reportTime,
			// 			indexDictId: item.id,
			// 			planItemId: formdata.planItemId
			// 		}
			// 	).then(res => {
			// 		if (res.value) {
			// 			let val = res.value
			// 			let data = _that.$refs.autoform.formdata
			// 			_that.$refs.autoform.changeEditor("title2","indexCategoryObjId","data",configSelectData(val.category,"indexCategoryObjId","indexCategoryObjName"))
			// 			_that.$refs.autoform.initSelectIndex("title2","indexCategoryObjId")
			// 			data.firstDate = val.firstDate
			// 			data.lastDate = val.lastDate
			// 			data.autoSum = val.autoSum
			// 			data.relationName = val.relationName
			// 			_that.$refs.autoform.changeEditor("title2","relationList","param", {relationList:JSON.stringify(data.relationList)})
			// 		}
			// 		if(res.value.category.length){
			// 			_that.$refs.autoform.changeEditor("title2","indexCategoryObjId","data",configSelectData(res.value.category,'indexCategoryObjId',"indexCategoryObjName"))
			// 			_that.$refs.autoform.initSelectIndex("title2","indexCategoryObjId")
			// 		}
			// 	})
			// },
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if(e.reportTime){
					_that.reportTime = e.reportTime
				}
				if(e.userId){
					_that.oUserId = e.userId
				}
				if (e.configDataCacheKey) {
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if (res.data && Object.prototype.toString.call(res.data) ===
								'[object Array]') {
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							
							var sdataList = [];
							var statisticalDataId = '';
							for (let i = 0; i < _that.datas.length; i++) {
								let row = _that.datas[i];
								if (row) {
									if (e.index && i == e.index) {
										statisticalDataId = row.id
									} else {
										sdataList.push(row)
									}
								}
							}
							
							changeEditor("title2","indexRegisterId",{
								link:'../../public/search/search',
								"linkParam":{
									method: 'POST',
									other:JSON.stringify({
										zuserId: _that.userId,
										reportTime: _that.reportTime,
										userId: _that.oUserId,
										dataStr: JSON.stringify(sdataList),
										modelListFlag: true,
										hasStatisticalDataId: statisticalDataId
									}),
									url:'anyTimeReport/findModeList',
									initload:true,
									namefield: 'indexDictName',
									cachename: _that.indexRegisterCache,
								}
							},null,_that.autoformdata)
							
							changeEditor("title2","relationList",'type',"routerbox",_that.autoformdata)
							changeEditor("title2","relationList",'url',"/pages/form/ckd-zb-anytimereport/showRelationList",_that.autoformdata)
							_that.initLoad()
						}
					})
				}
			})
			_that.$nextTick(function() {
				// if(e.edit == "true"){
				// 	_that.onSelectPlan(_that.$refs.autoform.formdata.planItemId)
				// }
				// if(_that.$refs.autoform.formdata.indexDictId &&  _that.$refs.autoform.formdata.indexUnitName){
				// 	_that.onSelectIndexDict({
				// 		id: _that.$refs.autoform.formdata.indexDictId,
				// 		indexUnitName: _that.$refs.autoform.formdata.indexUnitName
				// 	})
				// }
			})
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.indexRegisterCache,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.indexRegisterId = d.indexRegisterId
							formdata.indexDictName = d.indexDictName
							formdata.indexDictId = d.indexDictId
							formdata.customCateId = d.customCateId
							formdata.inputPrecision = d.inputPrecision
							formdata.indexCategoryObjId = d.indexCategoryObjId
							formdata.indexCategoryObjName = d.indexCategoryObjName
							formdata.indexUnitId = d.indexUnitId
							formdata.indexUnitName = d.indexUnitName
							formdata.userId = d.userId
							formdata.userName = d.userName
							formdata.postId = d.postId
							formdata.postName = d.postName
							formdata.instId = d.instId
							formdata.instName = d.instName
							formdata.statisticsFreqId = d.statisticsFreqId
							formdata.statisticsFreqName = d.statisticsFreqName
							formdata.firstDate = d.firstDate
							formdata.lastDate = d.lastDate
							formdata.targetValue = d.targetValue
							formdata.relationIndexStr = d.relationIndexStr
							formdata.relationName = d.relationName
							formdata.relationList = d.relationList
							formdata.autoSum = d.autoSum
							formdata.sum = d.autoSum
							// _that.onSelectIndexDict({id:d.id,indexUnitName:d.indexUnitName})
							uni.removeStorage({
								key:_that.indexRegisterCache
							})
						}
					}
				})
			}
		},
	}
</script>

<style>
</style>
